#pragma once

#include <stdexcept>
#include <Windows.h>
#include <string>

namespace DirectXCore {
	class DirectXException : public std::runtime_error {
		HRESULT mResult;
		std::string mApiName;
	public:
		DirectXException(HRESULT result, const char* apiName = "");
		HRESULT GetResult() const;
		const std::string& GetApiName() const;
	};

#define DX_CALL(apiCall) \
    { \
        HRESULT __hr__ = (apiCall); \
        if (FAILED(__hr__)) { \
            throw DirectXCore::DirectXException(__hr__, #apiCall); \
        } \
    }

#define DX_CALL_NAMED(apiCall, methodName) \
    { \
        HRESULT __hr__ = (apiCall); \
        if (FAILED(__hr__)) { \
            throw DirectXCore::DirectXException(__hr__, methodName); \
        } \
    }
}